<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Yahooorder extends CI_Controller {
    
	function __construct(){
		parent::__construct();
		$this->load->model('function_m','fun');
    }
	public function index(){
		$this -> tpl -> display("welcome_message.php",'','',1);
	}

	public function getorder(){

		$url = "https://test.circus.shopping.yahooapis.jp/ShoppingWebService/V1/orderCount?sellerId=border_3159";
		$OrderTimeFrom = "2017-02-25";
		$OrderTimeTo = "2017-02-27";
		$key = '62050eb2bfc3e6bda4a423d7350f347f1a1b0486';
		$SellerId = "dj0zaiZpPVFjRElkSVUzbnN4diZzPWNvbnN1bWVyc2VjcmV0Jng9Y2I-";
		$api = "https://test.circus.shopping.yahooapis.jp/ShoppingWebService/V1/orderList";
		$xml=<<<XML
        <Req> 
        <SellerId>$SellerId</SellerId>
        <Search>
        <Field>OrderId</Field>
        <Result>2000</Result>
        <Condition> 
        <OrderTimeFrom>$OrderTimeFrom</OrderTimeFrom>$OrderTimeTo
        </Condition></Search>
        </Req>
        XML;
		
		$headr = array(  
            "Authorization: Bearer ".$key,  
	  );
	
		
		
		$output=$this->fun->curlfunc($api,$xml,$cookie_jar,$headr);
		echo "<xmp>";
		print_r($output);
		echo "</xmp>";
		die;

		curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,true);  
		//curl_setopt($ch,CURLOPT_CAINFO,dirname(__FILE__).'/cacert.pem');  
		curl_setopt($ch, CURLOPT_POST, true);  
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
		curl_setopt($ch, CURLOPT_HTTPHEADER,$headr);   
		curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);  
	  
		$result = curl_exec($ch);  
		curl_close($ch);  
		echo 1;
		print_r($result);

		$orderList = json_decode(json_encode(simplexml_load_string($result)),TRUE);  
		echo 2;
		print_r($orderList);
		die;
		return $orderList;  
	}

	public function getneworder()
	{	
			
			$api = 'https://auth.login.yahoo.co.jp/yconnect/v1/token';
			$appid = 'dj0zaiZpPVFjRElkSVUzbnN4diZzPWNvbnN1bWVyc2VjcmV0Jng9Y2I-';
			$secret = '62050eb2bfc3e6bda4a423d7350f347f1a1b0486';
			$basicAuth=base64_encode($appid . ':' . $secret);
			$header = array(
			  "Content-Type: application/x-www-form-urlencoded",
			  "Authorization: Basic ". $basicAuth,
			);
			$params = array(
			   'grant_type' => 'authorization_code',
			   'code' => $code,
			   'redirect_uri' => 'http://192.168.1.66',
			);

			$url = $api.'?'.http_build_query($params);
			
		
			$user_agent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB7.5; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E)";
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, $url);
			curl_setopt($ch, CURLOPT_REFERER, $url);
			curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_HEADER, $header);
			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
			$output =curl_exec($ch);
			curl_close($ch);

			if ($output === FALSE) {
				return "cURL Error: line 78, ";
			}

			
			echo "<xmp>";
			print_r($output);
			echo "</xmp>";
			die;
		
		
			

		
	}
}
